/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package radiostationv4;

import javax.persistence.EntityManager;
/**
 *
 * @author KiKiWi
 */
public class DBManager {
    public static final EntityManager em=
            javax.persistence.Persistence.createEntityManagerFactory("RadioStationV4PU").createEntityManager();

    public static boolean DeletePlaylist(Playlist pl){
        try{
            em.getTransaction().begin();
            Playlist playlist=em.merge(pl);
            em.remove(playlist);
            em.getTransaction().commit();
            return true;
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
    }
    
    public static boolean ModifyPlaylist(Playlist pl){
        try{
            em.getTransaction().begin();
            em.merge(pl);
            em.getTransaction().commit();
            return true;
        }catch(Exception e){
            System.out.println(e);
            return false;
        }
    }
    
    public static boolean SavePlaylist(Playlist pl){
            try {
            em.getTransaction().begin();
            em.persist(pl);
            em.getTransaction().commit();
            }catch(Exception e){
                System.out.println(e); 
                return false;
            }
            return true;
    }
}
